feat: add 'opentelemetry-exporter-otlp-json-common' package#4996
feat: add 'opentelemetry-exporter-otlp-json-common' package#4996herin049 wants to merge 12 commits intoopen-telemetry:mainfrom
Conversation
a06e192 to
6a0c46f
Compare
...son-common/src/opentelemetry/exporter/otlp/json/common/_internal/metrics_encoder/__init__.py
Show resolved
Hide resolved
|
Thanks for this and the benchmarks! I like how it's laid out very similarly to the otlp-proto-common.
I believe they were moved to test_1.yml |
That was my goal, although I made a few alterations/simplifications. |
tammy-baylis-swi
left a comment
There was a problem hiding this comment.
Lgtm, would be great if others from the discussion to have a look too.
|
Hi, excited to see this progressing! We have a use case where OTLP JSON would be really valuable. We're building an observability pipeline where traces need to be both forwarded to a backend (Langfuse) and persisted to disk as OTLP JSON files for audit/replay purposes. The current from google.protobuf.json_format import MessageToJson
from opentelemetry.exporter.otlp.proto.common.trace_encoder import encode_spans
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace.export import SpanExportResult
class OTLPJsonSpanExporter(OTLPSpanExporter):
"""OTLPSpanExporter that sends OTLP JSON instead of protobuf."""
def export(self, spans):
try:
encoded = encode_spans(spans)
serialized = MessageToJson(encoded, preserving_proto_field_name=True)
self._session.headers["Content-Type"] = "application/json"
return self._export(serialized.encode("utf-8"))
except Exception:
return SpanExportResult.FAILUREThis works but depends on internal APIs (encode_spans, _export). Having an official Would love to see this merged. Happy to help test! |
pmcollins
left a comment
There was a problem hiding this comment.
Thanks for doing this. LGTM overall, just a concern about raising exceptions.
...son-common/src/opentelemetry/exporter/otlp/json/common/_internal/metrics_encoder/__init__.py
Show resolved
Hide resolved
...-exporter-otlp-json-common/src/opentelemetry/exporter/otlp/json/common/_internal/__init__.py
Show resolved
Hide resolved
exporter/opentelemetry-exporter-otlp-json-common/pyproject.toml
Outdated
Show resolved
Hide resolved
4a11376 to
f800e97
Compare
pmcollins
left a comment
There was a problem hiding this comment.
Lots of excellent functionality here, thanks. Before enabling, should address proto and json throwing exceptions on bad data. LGTM otherwise.
@pmcollins Thanks! I've created #5050. Do you have any preference over the two solutions I've outlined? |
Description
Follow up to #4910 to progress towards adding support for OTLP JSON.
Fixes #1003
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Does This PR Require a Contrib Repo Change?
Checklist: